/**
 * 
 */
package net.cloudcodex.client.home.view.panel;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.google.gwt.user.client.ui.Image;

/**
 * @author Daniel
 *
 */
public class NotificationIcone extends Image  {
	List<NotifMessage> notifications = new ArrayList<NotifMessage>() ;
	
	TooltipListener tooltipListener = new TooltipListener(20000);

	@SuppressWarnings("deprecation")
	public NotificationIcone() {
		super ("images/portevoix.png");
		this.addMouseListener( tooltipListener );
	}


	private String getMessage() {
		StringBuffer message = new StringBuffer() ; 
		for (NotifMessage notifAsString : notifications) {
			message.append(notifAsString.getNotifAsString() );
			message.append("<br/>");
		}
		return message.toString();
	}

	public void addNotification(String message, Date date) {
		notifications.add(new NotifMessage(message,date));
		tooltipListener.setText(getMessage());
	}


	public boolean hasNotifs() {
		return !notifications.isEmpty();
	}
	
	
}

class NotifMessage {
	private String message ;
	private Date date ;
	
	
	public NotifMessage(String message, Date date) {
		this.message = message ;
		this.date = date ;
	}

	protected String getNotifAsString(){
		return "[ "+date+" ] - " + message ;
	}
	
}
